﻿using Common;
using Newtonsoft.Json;
//using ServiceStack.Redis;
using StackExchange.Redis;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace RedisServer
{
    public class Program
    {
        static void Main(string[] args)
        {
            ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("127.0.0.1:6379");
            IDatabase dbContext = connection.GetDatabase();


            string listKey = "orderList";
           for (long i = 0; i<=dbContext.ListLength(listKey);i++)
            {
                Task.Run(() =>
                {
                    var listValue = dbContext.ListRightPop(listKey);
                    if (listValue != RedisValue.Null)
                    {
                        var order = JsonConvert.DeserializeObject<Orders>(listValue);
                        dbContext.ListRemove(listKey, listValue);
                        Thread.Sleep(1000);
                        Console.WriteLine($"{order.id} 已出货 剩余处理:{dbContext.ListLength(listKey)}");
                    }
                    
                });
            }
            Console.ReadLine();


        }
    }
}
